package com.library.service.impl;


import com.library.common.constant.UserConstants;
import com.library.common.core.text.Convert;
import com.library.common.utils.StringUtils;
import com.library.domain.BoMembers;
import com.library.mapper.BoMembersMapper;
import com.library.service.IBoMembersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * 图书管会员 服务层实现
 *
 * @author null
 * @date 2020-01-18
 */
@Service
public class BoMembersServiceImpl implements IBoMembersService {
    @Resource
    private BoMembersMapper boMembersMapper;

    /**
     * 查询图书管会员信息
     *
     * @param id 图书管会员ID
     * @return 图书管会员信息
     */
    @Override
    public BoMembers selectBoMembersById(Long id) {
        return boMembersMapper.selectBoMembersById(id);
    }

    /**
     * 查询图书管会员列表
     *
     * @param boMembers 图书管会员信息
     * @return 图书管会员集合
     */
    @Override
    public List<BoMembers> selectBoMembersList(BoMembers boMembers) {
        return boMembersMapper.selectBoMembersList(boMembers);
    }

    /**
     * 新增图书管会员
     *
     * @param boMembers 图书管会员信息
     * @return 结果
     */
    @Override
    public int insertBoMembers(BoMembers boMembers) {
        return boMembersMapper.insertBoMembers(boMembers);
    }

    /**
     * 修改图书管会员
     *
     * @param boMembers 图书管会员信息
     * @return 结果
     */
    @Override
    public int updateBoMembers(BoMembers boMembers) {
        return boMembersMapper.updateBoMembers(boMembers);
    }

    /**
     * 删除图书管会员对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteBoMembersByIds(Long ids) {
        return boMembersMapper.deleteBoMembersByIds(ids);
    }

    @Override
    public String checkLoginNameUnique(BoMembers members) {
        Long userId = StringUtils.isNull(members.getId()) ? -1L : members.getId();
        BoMembers info = boMembersMapper.checkLoginNameUnique(members.getMembersName());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != userId) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public String checkPhoneUnique(BoMembers members) {
        Long userId = StringUtils.isNull(members.getId()) ? -1L : members.getId();
        BoMembers info = boMembersMapper.checkPhoneUnique(members.getMembersPhone());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != userId) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public String checkNoUnique(BoMembers members) {
        Long id = StringUtils.isNull(members.getId()) ? -1L : members.getId();
        BoMembers boMembers = boMembersMapper.checkNoUnique(members.getMembersNo());
        if (StringUtils.isNotNull(boMembers) && boMembers.getId().longValue() != id) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public BoMembers selectByPhone(String phone) {
        return boMembersMapper.checkPhoneUnique(phone);
    }

}
